import { Selection } from '@/components/el/ItemComponent';
import React from 'react';
import request from '@/utils/request';
interface TransferProps {
  value: string;
  label: string;
}
interface Props {
  value?: any;
  onChange?: Function;
  transfer?: null;
  paramsData?: any;
  needFilterEs10: any;
  [props: string]: any;
}
const defaultTransfer: TransferProps = {
  value: 'id',
  label: 'sceneName'
};
// 在此处组装所有的数据
class PurSceneSelection extends React.Component<Props> {
  static defaultProps = {
    disabled: false,
    multiple: false,
    allowClear: true,
    transfer: defaultTransfer,
    selectRecord: false
  };
  /**
   * @description 构造器
   */
  constructor(props) {
    super(props);
  }
  componentDidMount() {}

  // 请求数据方法
  onRequest = async () => {
    const res = await request(`/yst-pur/pur/purscene/list`, {
      method: 'post',
      query: {
        orders: [{ asc: false, column: 'createTime' }],
        es6: 1,
        es8: 'A',
        ...this.props.paramsdata
      }
    });
    if (res?.success) {
      if (this.props.needFilterEs10) {
        const data = res?.data?.filter((item) => item.es10 !== 0);
        return {
          ...res,
          data
        };
      } else {
        return {
          ...res
        };
      }
    }
  };

  render() {
    return (
      <Selection
        {...this.props}
        onChange={this.props.onChange}
        request={this.onRequest}
      />
    );
  }
}
export default PurSceneSelection;
